﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MxWeiXinPF.Common;
using MxWeiXinPF.BLL;
using System.Text;
using System.Linq;
using System.Web.UI.HtmlControls;

namespace MxWeiXinPF.Web.shopmgr.product
{
    public partial class product_edit : MxWeiXinPF.Web.UI.ManagePage
    {
        private string action = MXEnums.ActionEnum.Add.ToString();
        protected MxWeiXinPF.Model.manager admin_info;
        public int catalogId = 0;
        private MxWeiXinPF.BLL.wx_shop_product spBll = new MxWeiXinPF.BLL.wx_shop_product();

        private List<MxWeiXinPF.Model.wx_shop_productAttr_value> AddAttr()
        {
            List<MxWeiXinPF.Model.wx_shop_productAttr_value> list = new List<MxWeiXinPF.Model.wx_shop_productAttr_value>();
            string strContent = this.hidAttrValueStr.Value;
            if ((strContent == null) || (strContent.Trim() == ""))
            {
                return null;
            }
            string[] strArray = Utils.SplitString(strContent, "||");
            MxWeiXinPF.Model.wx_shop_productAttr_value item = new MxWeiXinPF.Model.wx_shop_productAttr_value();
            foreach (string str2 in strArray)
            {
                if (str2.Length > 0)
                {
                    string[] strArray2 = Utils.SplitString(str2, "_");
                    if ((strArray2 != null) && (strArray2.Length > 0))
                    {
                        item = new MxWeiXinPF.Model.wx_shop_productAttr_value
                        {
                            attributeId = new int?(MyCommFun.Str2Int(strArray2[1])),
                            paValue = MyCommFun.ObjToStr(strArray2[3])
                        };
                        list.Add(item);
                    }
                }
            }
            return list;
        }

        private List<MxWeiXinPF.Model.wx_shop_sku> AddSku()
        {
            List<MxWeiXinPF.Model.wx_shop_sku> list = new List<MxWeiXinPF.Model.wx_shop_sku>();
            string strContent = this.hidSkuVauleStr.Value;
            if ((strContent == null) || (strContent.Trim() == ""))
            {
                return null;
            }
            string[] strArray = Utils.SplitString(strContent, "||");
            MxWeiXinPF.Model.wx_shop_sku item = new MxWeiXinPF.Model.wx_shop_sku();
            foreach (string str2 in strArray)
            {
                if (str2.Length > 0)
                {
                    string[] strArray2 = Utils.SplitString(str2, "_");
                    if ((strArray2 != null) && (strArray2.Length > 0))
                    {
                        item = new MxWeiXinPF.Model.wx_shop_sku
                        {
                            attributeId = new int?(MyCommFun.Str2Int(strArray2[1])),
                            price = new decimal?(MyCommFun.Str2Int(strArray2[3])),
                            attributeValue = MyCommFun.ObjToStr(strArray2[5])
                        };
                        list.Add(item);
                    }
                }
            }
            return list;
        }

        private void BindAttrHtml(int catalogId)
        {
            IList<MxWeiXinPF.Model.wx_shop_productAttr_value> oldskulist = new List<MxWeiXinPF.Model.wx_shop_productAttr_value>();
            IList<MxWeiXinPF.Model.wx_shop_sku> list2 = new List<MxWeiXinPF.Model.wx_shop_sku>();
            bool flag = false;
            bool flag2 = false;
            int num = MyCommFun.Str2Int(this.hidCatalogId.Value);
            int num2 = MyCommFun.Str2Int(this.hidid.Value);
            if (catalogId == num)
            {
                MxWeiXinPF.BLL.wx_shop_productAttr_value _value = new MxWeiXinPF.BLL.wx_shop_productAttr_value();
                MxWeiXinPF.BLL.wx_shop_sku _sku = new MxWeiXinPF.BLL.wx_shop_sku();
                oldskulist = _value.GetModelList("productId=" + num2);
                if ((oldskulist != null) && (oldskulist.Count > 0))
                {
                    flag = true;
                }
                list2 = _sku.GetModelList("productId=" + num2);
                if ((list2 != null) && (list2.Count > 0))
                {
                    flag2 = true;
                }
            }
            IList<MxWeiXinPF.Model.wx_shop_catalog_attribute> modelList = new MxWeiXinPF.BLL.wx_shop_catalog_attribute().GetModelList("catalogId=" + catalogId + " order by sort_id asc");
            if ((modelList != null) && (modelList.Count > 0))
            {
                MxWeiXinPF.Model.wx_shop_catalog_attribute _attribute2 = new MxWeiXinPF.Model.wx_shop_catalog_attribute();
                StringBuilder builder = new StringBuilder();
                string str = "";
                string str2 = "";
                for (int i = 0; i < modelList.Count; i++)
                {
                    string[] strArray;
                    int num4;
                    _attribute2 = modelList[i];
                    if (_attribute2.aType.Value == 1)
                    {
                        builder.Append("<dl>");
                        builder.Append(" <dt>" + _attribute2.aName + "</dt>");
                        builder.Append("<dd>");
                        if ((_attribute2.aValue == null) || (_attribute2.aValue.Trim() == ""))
                        {
                            if (flag)
                            {
                                str = this.porductAttrValue(_attribute2.id, oldskulist);
                                builder.Append(string.Concat(new object[] { "<input name=\"txtattr\" type=\"text\" id=\"extattr_", _attribute2.id, "\" value=\"", str, "\" attrid=\"", _attribute2.id, "\" class=\"input normal txt_attr \" datatype=\"*0-200\" sucmsg=\" \" nullmsg=\" \">" }));
                            }
                            else
                            {
                                builder.Append(string.Concat(new object[] { "<input name=\"txtattr\" type=\"text\" id=\"extattr_", _attribute2.id, "\" attrid=\"", _attribute2.id, "\" class=\"input normal txt_attr \" datatype=\"*0-200\" sucmsg=\" \" nullmsg=\" \">" }));
                            }
                        }
                        else
                        {
                            strArray = Utils.SplitString(_attribute2.aValue, "\r\n");
                            if ((strArray != null) && (strArray.Length > 0))
                            {
                                builder.Append(string.Concat(new object[] { "<select name=\"ddlattr\" id=\"extattr_", _attribute2.id, "\" attrid=\"", _attribute2.id, "\"  class=\"txt_attr\">" }));
                                builder.Append("<option value=\"\">请选择...</option>");
                                if (flag)
                                {
                                    str = this.porductAttrValue(_attribute2.id, oldskulist);
                                    num4 = 0;
                                    while (num4 < strArray.Length)
                                    {
                                        if (str == strArray[num4])
                                        {
                                            builder.Append("<option value=\"" + strArray[num4] + "\" selected=\"selected\">" + strArray[num4] + "</option>");
                                        }
                                        else
                                        {
                                            builder.Append("<option value=\"" + strArray[num4] + "\">" + strArray[num4] + "</option>");
                                        }
                                        num4++;
                                    }
                                }
                                else
                                {
                                    num4 = 0;
                                    while (num4 < strArray.Length)
                                    {
                                        builder.Append("<option value=\"" + strArray[num4] + "\">" + strArray[num4] + "</option>");
                                        num4++;
                                    }
                                }
                                builder.Append("</select>");
                            }
                            builder.Append("");
                        }
                        builder.Append("</dd>");
                        builder.Append("</dl>");
                    }
                    else if ((_attribute2.aType.Value == 2) && ((_attribute2.aValue != null) && (_attribute2.aValue.Trim() != "")))
                    {
                        builder.Append("<dl>");
                        builder.Append(" <dt>" + _attribute2.aName + "</dt>");
                        builder.Append("<dd>");
                        strArray = Utils.SplitString(_attribute2.aValue, "\r\n");
                        if ((strArray != null) && (strArray.Length > 0))
                        {
                            builder.Append(" <table class=\"ltable tb_sku\">  <thead> <tr> <th width=\"80\"> 使用 </th> <th> 名称  </th> <th width=\"120\">  属性加价格 </th> </tr></thead>");
                            builder.Append("<tbody class=\"ltbody\">");
                            for (num4 = 0; num4 < strArray.Length; num4++)
                            {
                                builder.Append(" <tr class=\"td_c\">");
                                if (flag2)
                                {
                                    str2 = this.porductSkuPrice(_attribute2.id, strArray[num4], list2);
                                    if (str2 != "")
                                    {
                                        builder.Append(" <td>");
                                        builder.Append(string.Concat(new object[] { "<input id=\"chk_skuvalue_", num4, "\" type=\"checkbox\" attrid=\"", _attribute2.id, "\" class=\"skuchk\" checked=\"checked\" />" }));
                                        builder.Append("</td>");
                                        builder.Append(string.Concat(new object[] { " <td> <label for=\"chk_skuvalue_", num4, "\" class=\"skuattrName\">", strArray[num4], "</label> </td>" }));
                                        builder.Append("<td>");
                                        builder.Append("<input name=\"txtaddvalue\" type=\"text\"   id=\"txtaddvalue" + strArray[num4] + "\" value=\"" + str2 + "\" class=\"input small skuvaddmenoy\" datatype=\"*0-10\" sucmsg=\" \">");
                                        builder.Append("</td>");
                                    }
                                    else
                                    {
                                        builder.Append(" <td>");
                                        builder.Append(string.Concat(new object[] { "<input id=\"chk_skuvalue_", num4, "\" type=\"checkbox\" attrid=\"", _attribute2.id, "\" class=\"skuchk\"   />" }));
                                        builder.Append("</td>");
                                        builder.Append(string.Concat(new object[] { " <td> <label for=\"chk_skuvalue_", num4, "\" class=\"skuattrName\">", strArray[num4], "</label> </td>" }));
                                        builder.Append("<td>");
                                        builder.Append("<input name=\"txtaddvalue\" type=\"text\"   id=\"txtaddvalue" + strArray[num4] + "\" value=\"0\" class=\"input small skuvaddmenoy\" datatype=\"*0-10\" sucmsg=\" \">");
                                        builder.Append("</td>");
                                    }
                                }
                                else
                                {
                                    builder.Append(" <td>");
                                    builder.Append(string.Concat(new object[] { "<input id=\"chk_skuvalue_", num4, "\" type=\"checkbox\" attrid=\"", _attribute2.id, "\" class=\"skuchk\"   />" }));
                                    builder.Append("</td>");
                                    builder.Append(string.Concat(new object[] { " <td> <label for=\"chk_skuvalue_", num4, "\" class=\"skuattrName\">", strArray[num4], "</label> </td>" }));
                                    builder.Append("<td>");
                                    builder.Append("<input name=\"txtaddvalue\" type=\"text\"   id=\"txtaddvalue" + strArray[num4] + "\" value=\"0\" class=\"input small skuvaddmenoy\" datatype=\"*0-10\" sucmsg=\" \">");
                                    builder.Append("</td>");
                                }
                                builder.Append("</tr>");
                            }
                            builder.Append(" </tbody> </table>");
                        }
                        builder.Append("</dd>");
                        builder.Append("</dl>");
                    }
                }
                this.litAttr.Text = builder.ToString();
            }
        }

        private void bindCatalog()
        {
            MxWeiXinPF.Model.manager weiXinCode = base.GetAdminInfo();
            IList<MxWeiXinPF.Model.wx_shop_catalog> modelList = new MxWeiXinPF.BLL.wx_shop_catalog().GetModelList("wid=" + "39");
            this.ddlCatalog.DataTextField = "cTitle";
            this.ddlCatalog.DataValueField = "id";
            this.ddlCatalog.DataSource = modelList;
            this.ddlCatalog.DataBind();
            this.ddlCatalog.Items.Insert(0, new ListItem("请选择商品类型", "0"));
        }

        private void BindProductInfo(int id)
        {
            this.hidid.Value = id.ToString();
            MxWeiXinPF.Model.wx_shop_product model = this.spBll.GetModel(id);
            if (model.categoryId.HasValue && (model.categoryId.ToString() != null))
            {
                this.ddlCategoryId.SelectedValue = model.categoryId.ToString();
            }
            this.hidCatalogId.Value = model.catalogId.ToString();
            this.txtproductName.Text = model.productName;
            this.txtsku.Text = model.sku;
            if (model.upselling)
            {
                this.radType.Items[0].Selected = true;
            }
            else
            {
                this.radType.Items[1].Selected = true;
            }
            if (model.latest)
            {
                this.cblActionType.Items[0].Selected = true;
            }
            if (model.hotsale)
            {
                this.cblActionType.Items[1].Selected = true;
            }
            if (model.recommended)
            {
                this.cblActionType.Items[2].Selected = true;
            }
            if (model.specialOffer)
            {
                this.cblActionType.Items[3].Selected = true;
            }
            this.txtcostPrice.Text = model.costPrice.ToString();
            this.txtmarketPrice.Text = model.marketPrice.ToString();
            this.txtsalePrice.Text = model.salePrice.ToString();
            this.txtstock.Text = model.stock.ToString();
            this.txtsort_id.Text = !model.sort_id.HasValue ? "99" : model.sort_id.ToString();
            this.txtshortDesc.Text = model.shortDesc;
            this.txtdescription.InnerText = model.description;
            this.txtspec.Text = model.spec;
            this.txtValidity.Text = model.validity;
            this.txtFactory.Text = model.factory;
            this.txtZhunzi.Text = model.zhunzi;
            this.txtSumQty.Text = model.sumqty.ToString();
            this.txtOneDayQty.Text = model.onedayqty.ToString();
            this.tbextstr1.Text = model.extstr2.ToString().Trim();
            if (model.issendmessage)
            {
                this.rdbIsSendMessage.SelectedIndex = 0;
            }
            else
            {
                this.rdbIsSendMessage.SelectedIndex = 1;
            }
            if (model.isRx)
            {
                this.rdbIsRx.SelectedIndex = 0;
            }
            else
            {
                this.rdbIsRx.SelectedIndex = 1;
            }
            this.txtDrugNumber.Text = model.drugnumber;
            this.rptAlbumList.DataSource = model.albums;
            this.rptAlbumList.DataBind();
            this.BindAttrHtml(model.catalogId);
        }

        private void BindProductInfoByChange(int id)
        {
            MxWeiXinPF.Model.wx_shop_product model = this.spBll.GetModel(id);
            if (model.categoryId.HasValue && (model.categoryId.ToString() != null))
            {
                this.ddlCategoryId.SelectedValue = model.categoryId.ToString();
            }
            this.hidCatalogId.Value = model.catalogId.ToString();
            this.txtproductName.Text = model.productName;
            this.txtsku.Text = model.sku;
            if (model.upselling)
            {
                this.radType.Items[0].Selected = true;
            }
            else
            {
                this.radType.Items[1].Selected = true;
            }
            if (model.latest)
            {
                this.cblActionType.Items[0].Selected = true;
            }
            if (model.hotsale)
            {
                this.cblActionType.Items[1].Selected = true;
            }
            if (model.recommended)
            {
                this.cblActionType.Items[2].Selected = true;
            }
            if (model.specialOffer)
            {
                this.cblActionType.Items[3].Selected = true;
            }
            this.txtcostPrice.Text = model.costPrice.ToString();
            this.txtmarketPrice.Text = model.marketPrice.ToString();
            this.txtsalePrice.Text = model.salePrice.ToString();
            this.txtstock.Text = model.stock.ToString();
            this.txtsort_id.Text = !model.sort_id.HasValue ? "99" : model.sort_id.ToString();
            this.txtshortDesc.Text = model.shortDesc;
            this.txtdescription.InnerText = model.description;
            this.txtspec.Text = model.spec;
            this.txtValidity.Text = model.validity;
            this.txtFactory.Text = model.factory;
            this.txtZhunzi.Text = model.zhunzi;
            this.txtSumQty.Text = model.sumqty.ToString();
            this.txtOneDayQty.Text = model.onedayqty.ToString();
            this.tbextstr1.Text = model.extstr2.ToString().Trim();
            if (model.issendmessage)
            {
                this.rdbIsSendMessage.SelectedIndex = 0;
            }
            else
            {
                this.rdbIsSendMessage.SelectedIndex = 1;
            }
            if (model.isRx)
            {
                this.rdbIsRx.SelectedIndex = 0;
            }
            else
            {
                this.rdbIsRx.SelectedIndex = 1;
            }
            this.txtDrugNumber.Text = model.drugnumber;
            this.rptAlbumList.DataSource = model.albums;
            this.rptAlbumList.DataBind();
            this.BindAttrHtml(model.catalogId);
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int id = MyCommFun.Str2Int(this.hidid.Value);
            string msgtitle = "";
            if (this.txtproductName.Text.Trim().Length == 0)
            {
                msgtitle = msgtitle + @"商品名称不能为空！\n";
            }
            if (!MyCommFun.isNumber(this.txtSumQty.Text))
            {
                msgtitle = msgtitle + @"商品总量格式错误！\n";
            }
            if (!MyCommFun.isNumber(this.txtOneDayQty.Text))
            {
                msgtitle = msgtitle + @"每日用量格式错误！\n";
            }
            if (!MyCommFun.isDecimal(this.txtcostPrice.Text))
            {
                msgtitle = msgtitle + @"成本格式错误！\n";
            }
            if (!MyCommFun.isDecimal(this.txtmarketPrice.Text))
            {
                msgtitle = msgtitle + @"市场价格式错误！\n";
            }
            if (!MyCommFun.isDecimal(this.txtsalePrice.Text))
            {
                msgtitle = msgtitle + @"销售价格式错误！\n";
            }
            if (!MyCommFun.isNumber(this.txtstock.Text))
            {
                msgtitle = msgtitle + @"库存格式错误！\n";
            }
            if (!MyCommFun.isNumber(this.txtsort_id.Text))
            {
                msgtitle = msgtitle + @"排序号格式错误！\n";
            }
            if (msgtitle != "")
            {
                base.JscriptMsg(msgtitle, "back", "Error");
            }
            else
            {
                int num8;
                int num2 = base.GetAdminInfo().id;
                int num3 = int.Parse(this.ddlCategoryId.SelectedItem.Value);
                int num4 = int.Parse(this.ddlCatalog.SelectedItem.Value);
                int num5 = 0;
                string text = this.txtsku.Text;
                if (text.Trim() == "")
                {
                    text = Utils.Number(8, true);
                }
                string str3 = this.txtproductName.Text;
                string str4 = this.txtshortDesc.Text;
                string str5 = "";
                decimal num6 = 0M;
                string str6 = this.txtdescription.Value;
                bool flag = false;
                bool flag2 = false;
                bool flag3 = false;
                bool flag4 = false;
                int count = this.cblActionType.Items.Count;
                for (num8 = 0; num8 < count; num8++)
                {
                    if (this.cblActionType.Items[num8].Selected)
                    {
                        if (this.cblActionType.Items[num8].Value == "latest")
                        {
                            flag2 = true;
                        }
                        else if (this.cblActionType.Items[num8].Value == "hotsale")
                        {
                            flag3 = true;
                        }
                        else if (this.cblActionType.Items[num8].Value == "recommended")
                        {
                            flag = true;
                        }
                        else if (this.cblActionType.Items[num8].Value == "specialOffer")
                        {
                            flag4 = true;
                        }
                    }
                }
                decimal num9 = decimal.Parse(this.txtcostPrice.Text);
                decimal num10 = decimal.Parse(this.txtmarketPrice.Text);
                decimal num11 = decimal.Parse(this.txtsalePrice.Text);
                bool flag5 = true;
                if (this.radType.SelectedItem.Value == "2")
                {
                    flag5 = false;
                }
                int num12 = int.Parse(this.txtstock.Text);
                DateTime now = DateTime.Now;
                int num13 = 0;
                int num14 = int.Parse(this.txtsort_id.Text);
                DateTime time2 = DateTime.Now;
                int num15 = 0;
                if (GetRelativeAdminInfo() != null)
                {
                    num15 = GetRelativeAdminInfo().id;
                }
                else
                {
                    num15 = GetAdminInfo().id;
                }
                string str7 = this.txtspec.Text.Trim();
                string str8 = this.txtValidity.Text.Trim();
                string str9 = this.txtFactory.Text.Trim();
                string str10 = this.txtZhunzi.Text.Trim();
                int num16 = int.Parse(this.txtSumQty.Text.Trim());
                int num17 = int.Parse(this.txtOneDayQty.Text.Trim());
                string str11 = this.txtDrugNumber.Text.Trim();
                bool flag6 = false;
                if (this.rdbIsSendMessage.SelectedItem.Value == "1")
                {
                    flag6 = true;
                }
                MxWeiXinPF.Model.wx_shop_product model = this.spBll.GetModel(id);
                model.categoryId = new int?(num3);
                model.brandId = new int?(num5);
                model.sku = text;
                model.productName = str3;
                model.shortDesc = str4;
                model.unit = str5;
                model.weight = new decimal?(num6);
                model.description = str6;
                model.recommended = flag;
                model.latest = flag2;
                model.hotsale = flag3;
                model.specialOffer = flag4;
                model.costPrice = new decimal?(num9);
                model.marketPrice = new decimal?(num10);
                model.salePrice = new decimal?(num11);
                model.upselling = flag5;
                model.stock = new int?(num12);
                model.addDate = new DateTime?(now);
                model.vistiCounts = new int?(num13);
                model.sort_id = new int?(num14);
                model.updateDate = new DateTime?(time2);
                model.catalogId = num4;
                //model.shopid = num15;
                model.spec = str7;
                model.validity = str8;
                model.factory = str9;
                model.zhunzi = str10;
                model.sumqty = num16;
                model.onedayqty = num17;
                model.issendmessage = flag6;
                model.drugnumber = str11;
                model.extstr2 = this.tbextstr1.Text.Trim();
                bool flag7 = false;
                if (this.rdbIsRx.SelectedItem.Value == "1")
                {
                    flag7 = true;
                }
                model.isRx = flag7;
                if (model.albums != null)
                {
                    model.albums.Clear();
                }
                string[] values = base.Request.Form.GetValues("hid_photo_name");
                string[] strArray2 = base.Request.Form.GetValues("hid_photo_remark");
                string[] strArray3 = base.Request.Form.GetValues("hid_photo_isdefault");
                string str12 = "0";
                if (values != null)
                {
                    if (strArray3.Contains("1"))
                    {
                        str12 = "1";
                    }
                    List<MxWeiXinPF.Model.wx_shop_albums> list = new List<MxWeiXinPF.Model.wx_shop_albums>();
                    for (num8 = 0; num8 < values.Length; num8++)
                    {
                        string[] strArray4 = values[num8].Split(new char[] { '|' });
                        int num18 = Utils.StrToInt(strArray4[0], 0);
                        if (strArray4.Length == 3)
                        {
                            if (!string.IsNullOrEmpty(strArray2[num8]))
                            {
                                if (str12.Equals("1"))
                                {
                                    if (!string.IsNullOrEmpty(strArray3[num8]))
                                    {
                                        MxWeiXinPF.Model.wx_shop_albums item = new MxWeiXinPF.Model.wx_shop_albums
                                        {
                                            id = num18,
                                            productId = id,
                                            original_path = strArray4[1],
                                            thumb_path = strArray4[2],
                                            remark = strArray2[num8],
                                            isdefault = strArray3[num8]
                                        };
                                        list.Add(item);
                                    }
                                    else
                                    {
                                        MxWeiXinPF.Model.wx_shop_albums _albums2 = new MxWeiXinPF.Model.wx_shop_albums
                                        {
                                            id = num18,
                                            productId = id,
                                            original_path = strArray4[1],
                                            thumb_path = strArray4[2],
                                            remark = strArray2[num8],
                                            isdefault = "0"
                                        };
                                        list.Add(_albums2);
                                    }
                                }
                                else if (num8 == 0)
                                {
                                    MxWeiXinPF.Model.wx_shop_albums _albums3 = new MxWeiXinPF.Model.wx_shop_albums
                                    {
                                        id = num18,
                                        productId = id,
                                        original_path = strArray4[1],
                                        thumb_path = strArray4[2],
                                        remark = strArray2[num8],
                                        isdefault = "1"
                                    };
                                    list.Add(_albums3);
                                }
                                else
                                {
                                    MxWeiXinPF.Model.wx_shop_albums _albums4 = new MxWeiXinPF.Model.wx_shop_albums
                                    {
                                        id = num18,
                                        productId = id,
                                        original_path = strArray4[1],
                                        thumb_path = strArray4[2],
                                        remark = strArray2[num8],
                                        isdefault = "0"
                                    };
                                    list.Add(_albums4);
                                }
                            }
                            else if (str12.Equals("1"))
                            {
                                if (!string.IsNullOrEmpty(strArray3[num8]))
                                {
                                    MxWeiXinPF.Model.wx_shop_albums _albums5 = new MxWeiXinPF.Model.wx_shop_albums
                                    {
                                        id = num18,
                                        productId = id,
                                        original_path = strArray4[1],
                                        thumb_path = strArray4[2],
                                        isdefault = strArray3[num8]
                                    };
                                    list.Add(_albums5);
                                }
                                else
                                {
                                    MxWeiXinPF.Model.wx_shop_albums _albums6 = new MxWeiXinPF.Model.wx_shop_albums
                                    {
                                        id = num18,
                                        productId = id,
                                        original_path = strArray4[1],
                                        thumb_path = strArray4[2],
                                        isdefault = "0"
                                    };
                                    list.Add(_albums6);
                                }
                            }
                            else if (num8 == 0)
                            {
                                MxWeiXinPF.Model.wx_shop_albums _albums7 = new MxWeiXinPF.Model.wx_shop_albums
                                {
                                    id = num18,
                                    productId = id,
                                    original_path = strArray4[1],
                                    thumb_path = strArray4[2],
                                    isdefault = "1"
                                };
                                list.Add(_albums7);
                            }
                            else
                            {
                                MxWeiXinPF.Model.wx_shop_albums _albums8 = new MxWeiXinPF.Model.wx_shop_albums
                                {
                                    id = num18,
                                    productId = id,
                                    original_path = strArray4[1],
                                    thumb_path = strArray4[2],
                                    isdefault = "0"
                                };
                                list.Add(_albums8);
                            }
                        }
                    }
                    model.albums = list;
                }
                model.attrs = this.AddAttr();
                model.skulist = this.AddSku();
                new MxWeiXinPF.BLL.wx_shop_product().Update(model);
                base.AddAdminLog(MXEnums.ActionEnum.Edit.ToString(), "编辑商品信息，商品信息主键id:" + id);
                string url = MyCommFun.QueryString("frompage");
                base.JscriptMsg("***商品编辑成功***！", url, "Success");
            }
        }

        protected void ddlCatalog_SelectedIndexChanged(object sender, EventArgs e)
        {
            int catalogId = MyCommFun.Str2Int(this.ddlCatalog.SelectedItem.Value);
            this.BindAttrHtml(catalogId);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                int id = MyCommFun.RequestInt("id");
                if (id == 0)
                {
                    base.JscriptMsg("传输参数不正确！", "back", "Error");
                }
                else if (!this.Page.IsPostBack)
                {
                    this.admin_info = base.GetAdminInfo();
                    string str = MyCommFun.QueryString("frompage");
                    if (str != "")
                    {
                        this.litReturnPage.Text = "<a href=\"" + str + "\" class=\"back\"><i></i><span>返回</span></a>";
                    }
                    this.TreeBind();
                    this.bindCatalog();
                    this.BindProductInfo(id);
                }

            }
            catch (Exception ex)
            {

            }
        }

        private string porductAttrValue(int attributeId, IList<MxWeiXinPF.Model.wx_shop_productAttr_value> oldskulist)
        {
            string paValue = "";
            IList<MxWeiXinPF.Model.wx_shop_productAttr_value> list = oldskulist.Where<MxWeiXinPF.Model.wx_shop_productAttr_value>(delegate(MxWeiXinPF.Model.wx_shop_productAttr_value e)
            {
                int? nullable1 = e.attributeId;
                int num = attributeId;
                return ((nullable1.GetValueOrDefault() == num) && nullable1.HasValue);
            }).ToArray<MxWeiXinPF.Model.wx_shop_productAttr_value>();
            if ((list != null) && (list.Count > 0))
            {
                paValue = list[0].paValue;
            }
            return paValue;
        }

        private string porductSkuPrice(int attributeId, string attributeValue, IList<MxWeiXinPF.Model.wx_shop_sku> oldskulist)
        {
            string str = "";
            IList<MxWeiXinPF.Model.wx_shop_sku> list = oldskulist.Where<MxWeiXinPF.Model.wx_shop_sku>(delegate(MxWeiXinPF.Model.wx_shop_sku e)
            {
                int? nullable1 = e.attributeId;
                int num = attributeId;
                return (((nullable1.GetValueOrDefault() == num) && nullable1.HasValue) && (e.attributeValue == attributeValue));
            }).ToArray<MxWeiXinPF.Model.wx_shop_sku>();
            if ((list != null) && (list.Count > 0))
            {
                str = !list[0].price.HasValue ? "0" : list[0].price.ToString();
            }
            return str;
        }

        protected void rptAlbumList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = Convert.ToInt32(((HiddenField)e.Item.FindControl("hidpid")).Value);
            MxWeiXinPF.Model.wx_shop_albums model = new MxWeiXinPF.BLL.wx_shop_albums().GetModel(id);
            string commandName = e.CommandName;
        }

        private void TreeBind()
        {
            MxWeiXinPF.Model.manager weiXinCode = base.GetAdminInfo();
            DataTable wCodeList = new MxWeiXinPF.BLL.wx_shop_category().GetWCodeList(39, 0);
            this.ddlCategoryId.Items.Clear();
            this.ddlCategoryId.Items.Add(new ListItem("请选择类别...", ""));
            foreach (DataRow row in wCodeList.Rows)
            {
                string str = row["id"].ToString();
                int num = int.Parse(row["class_layer"].ToString());
                string text = row["title"].ToString().Trim();
                if (num == 1)
                {
                    this.ddlCategoryId.Items.Add(new ListItem(text, str));
                }
                else
                {
                    text = "├ " + text;
                    text = Utils.StringOfChar(num - 1, "　") + text;
                    this.ddlCategoryId.Items.Add(new ListItem(text, str));
                }
            }
        }

        protected void txtsku_TextChanged(object sender, EventArgs e)
        {
            try
            {
                if (!this.txtsku.Text.Trim().Equals(""))
                {
                    int maxIdByCode = new MxWeiXinPF.BLL.wx_shop_product().GetMaxIdByCode(this.txtsku.Text.Trim());
                    if (maxIdByCode > 0)
                    {
                        this.BindProductInfoByChange(maxIdByCode);
                    }
                }
            }
            catch (Exception ex)
            {
                
            }

        }
    }
}